1
|
|
|
import React from 'react'; |
2
|
|
|
import LanguageContainer from '../Language/Container'; |
3
|
|
|
import ListenerAdapter from '../Observer/ListenerAdapter'; |
4
|
|
|
import Observer, {IObserverAdapter} from '../Observer/Observer'; |
5
|
|
|
import RouterContainer from '../Router/Container'; |
6
|
|
|
import DataStorage from '../Storage/DataStorage'; |
7
|
|
|
import ThemeContainer from '../Theme/Container'; |
8
|
|
|
import Action from './Action'; |
9
|
|
|
import Application, {IAdapter} from './Application'; |
10
|
|
|
import ModuleLoader from './ModuleLoader'; |
11
|
|
|
import ApplicationPresenter from './View/Application/Presenter'; |
12
|
|
|
import StyleUrlFormatter from './View/Application/StyleUrlFormatter'; |
13
|
|
|
import PagePresenter from './View/Page/Presenter'; |
14
|
|
|
import SideMenuPresenter from './View/SideMenu/Presenter'; |
15
|
|
|
import TopBarPresenter from './View/TopBar/Presenter'; |
16
|
|
|
|
17
|
|
|
class Container { |
18
|
|
|
language: typeof LanguageContainer; |
19
|
|
|
theme: typeof ThemeContainer; |
20
|
|
|
applicationPresenter: ApplicationPresenter; |
21
|
|
|
topAppBarPresenter: TopBarPresenter; |
22
|
|
|
applicationAction: Action; |
23
|
|
|
menuOpenStateAdapter: IObserverAdapter<boolean>; |
24
|
|
|
menuOpenState: Observer<boolean>; |
25
|
|
|
sideMenuPresenter: SideMenuPresenter; |
26
|
|
|
moduleStateAdapter: ListenerAdapter<typeof React.Component | null>; |
27
|
|
|
moduleState: Observer<typeof React.Component | null>; |
28
|
|
|
moduleLoader: ModuleLoader; |
29
|
|
|
pagePresenter: PagePresenter; |
30
|
|
|
applicationActionAdapter: IAdapter; |
31
|
|
|
storage: DataStorage; |
32
|
|
|
styleUrlFormatter: StyleUrlFormatter; |
33
|
|
|
application: Application; |
34
|
|
|
|
35
|
|
|
constructor() { |
36
|
1 |
|
this.storage = new DataStorage('application', window.localStorage); |
37
|
1 |
|
this.language = LanguageContainer; |
38
|
1 |
|
this.theme = ThemeContainer; |
39
|
|
|
|
40
|
1 |
|
this.menuOpenStateAdapter = {onChange: (newValue: boolean) => {}}; |
41
|
1 |
|
this.menuOpenState = new Observer<boolean>( |
42
|
|
|
this.storage.loadData<boolean>('menuOpenState', false), |
43
|
|
|
this.storage.attach<boolean>('menuOpenState', this.menuOpenStateAdapter) |
44
|
|
|
); |
45
|
|
|
|
46
|
1 |
|
this.moduleStateAdapter = new ListenerAdapter<typeof React.Component | null>(); |
47
|
1 |
|
this.moduleState = new Observer<typeof React.Component | null>(null, this.moduleStateAdapter); |
48
|
1 |
|
this.moduleLoader = new ModuleLoader('../', this.moduleState); |
49
|
|
|
|
50
|
1 |
|
this.applicationAction = new Action( |
51
|
|
|
this.menuOpenState, |
52
|
|
|
RouterContainer.observer, |
53
|
|
|
RouterContainer.router, |
54
|
|
|
RouterContainer.registry, |
55
|
|
|
RouterContainer.adapter, |
56
|
|
|
this.moduleLoader |
57
|
|
|
); |
58
|
1 |
|
this.applicationActionAdapter = this.applicationAction.adapter; |
59
|
|
|
|
60
|
1 |
|
this.topAppBarPresenter = new TopBarPresenter(this.language.activeTranslator); |
61
|
1 |
|
this.sideMenuPresenter = new SideMenuPresenter( |
62
|
|
|
this.menuOpenState, |
63
|
|
|
this.language.activeTranslator, |
64
|
|
|
RouterContainer.observer, |
65
|
|
|
RouterContainer.registry |
66
|
|
|
); |
67
|
1 |
|
this.pagePresenter = new PagePresenter(this.moduleState); |
68
|
1 |
|
this.styleUrlFormatter = new StyleUrlFormatter(RouterContainer.observer); |
69
|
1 |
|
this.applicationPresenter = new ApplicationPresenter( |
70
|
|
|
this.theme.currentTheme, |
71
|
|
|
this.topAppBarPresenter, |
72
|
|
|
this.sideMenuPresenter, |
73
|
|
|
this.pagePresenter, |
74
|
|
|
this.styleUrlFormatter |
75
|
|
|
); |
76
|
|
|
|
77
|
1 |
|
this.application = new Application(this.applicationActionAdapter, this.applicationPresenter); |
78
|
|
|
|
79
|
1 |
|
RouterContainer.adapter.addListener(this.applicationActionAdapter.onPageChanged); |
80
|
1 |
|
this.application.attachToLanguage(this.language.adapter); |
81
|
1 |
|
this.application.attachToMenuOpenState(this.menuOpenStateAdapter); |
82
|
1 |
|
this.application.attachToModuleState(this.moduleStateAdapter); |
83
|
|
|
|
84
|
|
|
//Debug - SideAccess |
85
|
|
|
// @ts-ignore |
86
|
1 |
|
window.ApplicationContainer = this; |
87
|
|
|
// @ts-ignore |
88
|
1 |
|
window.RouterContainer = RouterContainer; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
export default new Container(); |
93
|
|
|
|